package com.winner.fastdfs.controller;

import com.winner.fastdfs.config.FastDFSClientWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * springboot 整合 tobato 的 fastdfs 实现文件上传和下载
 * https://www.cnblogs.com/javaju/archive/2019/11/16/11871950.html
 */
@Slf4j
@RestController
@RequestMapping("/")
public class FileController {

    @Autowired
    private FastDFSClientWrapper dfsClient;

    /**
     * http://localhost:8080/uploadFile
     */
    @PostMapping("/uploadFile")
    public Object uploadFile(MultipartFile file) throws IOException {
        String fileUrl  = dfsClient.uploadFile(file);
        return fileUrl;
    }

}